package com.ifp.opengate.boot.validator.service;

import org.springframework.stereotype.Component;

import com.ifp.opengate.boot.bean.ValidateEntity;
import com.ifp.opengate.boot.bean.ValidatorForm;
import com.ifp.opengate.boot.validator.constants.ValidatorConstants;

import cn.hutool.core.lang.PatternPool;
import cn.hutool.core.util.ReUtil;

/**
 * @description:邮箱格式校验
 * @create: 2020/3/14
 */
@Component
public class EmailValidateServiceImpl extends ValidateServiceImpl {

    @Override
    public ValidateEntity validateValue(ValidatorForm validatorForm, Object data) {
        if (data == null || data instanceof String) {
            return new ValidateEntity(ValidatorConstants.DEFAULT_ERROR_CODE, validatorForm.getErrorMsg(), data,
                validatorForm.getParamName());
        }
        if (!ReUtil.isMatch(PatternPool.EMAIL, (String)data)) {
            return new ValidateEntity(ValidatorConstants.DEFAULT_ERROR_CODE, validatorForm.getErrorMsg(), data,
                validatorForm.getParamName());
        }
        return null;
    }

}